package com.flyduck.mall.ums.dubbo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.mall.common.core.utils.BeanUtils;
import com.flyduck.mall.ums.api.RemoteAddressService;
import com.flyduck.mall.ums.domain.UmsAddress;
import com.flyduck.mall.ums.mapper.UmsAddressMapper;
import com.flyduck.mall.ums.api.vo.RemoteAddressRespVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * RemoteAddressServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-22
 */
@Slf4j
@DubboService
public class RemoteAddressServiceImpl implements RemoteAddressService {

    @Resource
    private UmsAddressMapper umsAddressMapper;

    @Override
    public RemoteAddressRespVO getDefaultAddressByUserId(Long userId) {
        UmsAddress umsAddress = umsAddressMapper.selectOne(
                new LambdaQueryWrapper<UmsAddress>()
                        .eq(UmsAddress::getUserId, userId)
                        .eq(UmsAddress::getIsDefault, true)
        );
        return BeanUtils.toBean(umsAddress,RemoteAddressRespVO.class);
    }

    @Override
    public RemoteAddressRespVO getAddressById(Long id) {
        UmsAddress umsAddress = umsAddressMapper.selectById(id);
        return BeanUtils.toBean(umsAddress,RemoteAddressRespVO.class);
    }
}
